import React from 'react'
import { Table, Button } from 'antd'
import { useHistory } from 'react-router-dom';

export default function NewsPublish(props) {

    const history = useHistory()
    const columns = [
        {
            title: '新闻标题',
            dataIndex: 'title',
            render: (title, item) => <Button type='link' onClick={() => history.push(`/news-manage/preview/${item.id}`, item)}>{title}</Button>
        },
        {
            title: '作者',
            dataIndex: 'author'
        },
        {
            title: '新闻分类',
            dataIndex: 'categoryName',
        },
        {
            title: '操作',
            //具体要展示什么按钮 由父组件决定 并把子组件id传给父组件
            render: (item) => props.button(item.id)
        },
    ];

    return (
        <div>
            <Table dataSource={props.dataSource} columns={columns} rowKey={(item) => item.id} pagination={{ pageSize: 5 }} />
        </div>
    )
}

